package com.ems.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;


/**
 * 实例化任务线程池
 * 完成自定义任务的实现
 * Scheduler：计划、调度器
 */
@Configuration
public class ThreadPoolTaskSchedulerUtil {

    @Bean ( name = "threadPoolTaskScheduler" )
    public ThreadPoolTaskScheduler threadPoolTaskScheduler () {
        ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler ();
        threadPoolTaskScheduler.setPoolSize ( 20 );                        // 线程池大小
        threadPoolTaskScheduler.setThreadNamePrefix ( "taskExecutor-" );   // 线程名称
        threadPoolTaskScheduler.setAwaitTerminationSeconds ( 600 );         // 等待时长
        threadPoolTaskScheduler.setWaitForTasksToCompleteOnShutdown ( true );  // 调度器shutdown被调用时等待当前被调度的任务完成
        return threadPoolTaskScheduler;
    }
}
